﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SCP_UNA_MVC.Libs;
using SCP_UNA_MVC.Models;
using System.Net.Mail;

namespace SCP_UNA_MVC.Controllers
{
    public class ContatoController : DefaultController
    {
        //
        // GET: /Contato/
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult EnviaEmail(FormCollection collection)
        {
            string erro = string.Empty;

            try
            {
                SmtpClient smtp = new SmtpClient();
                MailMessage mail = new MailMessage(collection["email"], "mailing@compreconstrua.com.br");
                mail.Subject = collection["assunto"];
                mail.IsBodyHtml = true;
                mail.Body = string.Format(collection["mensagem"]);
                smtp.Send(mail);
            }
            catch (Exception e)
            {
                erro = e.Message;
            }

            return Json(new
            {
                cliente = collection["nome"],
                erro = erro
            }, JsonRequestBehavior.AllowGet);
        }
    }
}
